package cn.lblbc.appassit.utils

import android.content.Context
import android.text.InputType
import android.widget.EditText
import android.widget.LinearLayout
import androidx.appcompat.app.AlertDialog
import cn.lblbc.appassit.model.AppInfo

/**
 * 文件名输入对话框工具类
 */
class FileNameInputDialog(private val context: Context) {
    
    /**
     * 显示单个应用的文件名输入对话框
     */
    fun showSingleAppFileNameDialog(
        appInfo: AppInfo,
        onConfirm: (customFileName: String?) -> Unit
    ) {
        val layout = LinearLayout(context).apply {
            orientation = LinearLayout.VERTICAL
            setPadding(50, 40, 50, 10)
        }
        
        // 输入框
        val editText = EditText(context).apply {
            hint = "例如：${appInfo.appName}"
            inputType = InputType.TYPE_CLASS_TEXT
            setSingleLine(true)
        }
        layout.addView(editText)
        
        AlertDialog.Builder(context)
            .setTitle("自定义文件名")
            .setView(layout)
            .setPositiveButton("确定") { _, _ ->
                val customName = editText.text.toString().trim()
                onConfirm(if (customName.isBlank()) null else customName)
            }
            .setNegativeButton("取消", null)
            .show()
    }
}